/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package controlador;

import Beans.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author USUARIO
 */
public class ServletPasajes1 extends HttpServlet {

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String accion = request.getParameter("accion");
        String origen = request.getParameter("pOri");
        String destino = request.getParameter("pDes");
        String tipPas = request.getParameter("pTipPas");
        HttpSession sesion = request.getSession();
        try {
            if(accion.equals("showIti"))
            {   ArrayList<ModIti_Servicios> list;
                ArrayList<ModIti_Servicios> listv;
                if(sesion.getAttribute("sesBoletos") != null && sesion.getAttribute("sesBoletosV") != null)
                {   list = (ArrayList<ModIti_Servicios>)sesion.getAttribute("sesBoletos");
                    listv = (ArrayList<ModIti_Servicios>)sesion.getAttribute("sesBoletosV");
                } else
                {   list = new ArrayList<ModIti_Servicios>();
                    listv = new ArrayList<ModIti_Servicios>();
                }
                if(tipPas.equals("Ida"))
                {
                    ModIti_Ruta r = new ModIti_Ruta();
                    ModIti_Ruta r1 = new ModIti_Ruta();
                    r = r1.obtenerIdRutaByOriDest(origen, destino);
                    ModIti_Servicios s = new ModIti_Servicios();
                    list = s.listarServiciosByIdRuta(r.getId());
                    sesion.setAttribute("sesBoletos", list);
                    response.sendRedirect("modulos/pasajes/pasajesPaso1.jsp");
                } else
                {   ModIti_Ruta rv = new ModIti_Ruta();
                    ModIti_Ruta rv1 = new ModIti_Ruta();
                    rv = rv1.obtenerIdRutaByOriDest(destino, origen);
                    ModIti_Servicios s = new ModIti_Servicios();
                    list = s.listarServiciosByIdRuta(rv.getId());
                    sesion.setAttribute("sesBoletosV", listv);
                    response.sendRedirect("modulos/pasajes/pasajesPaso1.jsp");
                }
            }            
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
